package cn;

import cn.webrx.entity.Book;
import cn.webrx.mapper.BookMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>功能描述: </p>
 *
 * @author webrx
 * @version 1.0
 * @date 2020-09-14 16:41
 */
public class Demo {
    public static void main(String[] args) throws IOException {
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession ss = factory.openSession();

        BookMapper bookdao = ss.getMapper(BookMapper.class);
        //添加
        //Book java = new Book(0,"《java挑战开发入》",80d,"James Gosliing", LocalDate.of(1999,10,28));
        //int num = bookdao.add(java);
        //System.out.println(num);
        //ss.commit();

        //删除
        int nn = bookdao.deleteById(39);
        System.out.println(nn);



        //修改
        Book mys = bookdao.queryById(34);
        mys.setPrice(100);
        bookdao.update(mys);

        ss.commit();




        //查询
        for(Book book : bookdao.queryAll()){
            System.out.println(book.getName());
        }
    }
}
